package com.algorithms.datatypes;

import com.algorithms.absdatatypes.Apply;
import com.algorithms.absdatatypes.TreeNode;
import com.algorithms.absdatatypes.TreeTraversal;

public class TreeTraversalImpl implements TreeTraversal
{

	@Override
	public <T> void enumerateAll(TreeNode<T> treenode,Apply.TREE_TRAVERSAL traversal)
	{
		
		if(traversal.equals(Apply.TREE_TRAVERSAL.ROOTLEFTCHILDTORIGHTCHILD))
		{
			if(!treenode.isVisited())
			{
				treenode.setVisited(true);
				System.out.println(treenode.getData());
				if(treenode.getChildren()!=null)
				{
					for(TreeNode<T> child: treenode.getChildren())
					{
						enumerateAll(child,Apply.TREE_TRAVERSAL.ROOTLEFTCHILDTORIGHTCHILD);
					}
				}
			}
		}
		if(traversal.equals(Apply.TREE_TRAVERSAL.LEFTCHILDTORIGHTCHILDROOT))
		{
			if(!treenode.isVisited())
			{
				treenode.setVisited(true);
				
				if(treenode.getChildren()!=null)
				{
					for(TreeNode<T> child: treenode.getChildren())
					{
						enumerateAll(child,Apply.TREE_TRAVERSAL.LEFTCHILDTORIGHTCHILDROOT);
					}
				}
				System.out.println(treenode.getData());
			}
		}
	}

	@Override
	public <T> TreeNode<T> findItem(T item)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> TreeNode<T> findRoot()
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> void deleteItem(T item)
	{
		// TODO Auto-generated method stub
		
	}

}
